package com.gc.widget;

import android.graphics.Bitmap;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class OilCanClient extends WebViewClient {
	
	/**
	 * Watch each newly loaded page for userscript extensions (.user.js) to
	 * prompt user with install helper.
	 */
	public void onPageStarted(WebView view, final String url, Bitmap favicon) {
		/*
		// if url matches userscript extension, launch installer helper dialog
		if(url.endsWith(BrowserActivity.USERSCRIPT_EXTENSION)) {
			new AlertDialog.Builder(BrowserActivity.this)
				.setTitle(R.string.install_title)
				.setMessage(getString(R.string.install_message, url))
				.setPositiveButton(android.R.string.ok, new OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						try {
							String raw = Util.getUrlString(url);
							scriptdb.insertScript(null, raw);
							Toast.makeText(BrowserActivity.this, R.string.manage_import_success, Toast.LENGTH_SHORT).show();
						} catch(Exception e) {
							Log.e(TAG, "Problem while trying to import script", e);
							Toast.makeText(BrowserActivity.this, R.string.manage_import_fail, Toast.LENGTH_SHORT).show();
						}
					}
				}).setNegativeButton(android.R.string.cancel, null).create().show();
			
		}
*/
	}
	
	/**
	 * Handle finished loading of each page. Specifically this checks for
	 * any active scripts based on the URL. When found a matching site, we
	 * inject the JSON library and the applicable script.
	 */
	public void onPageFinished(WebView view, String url) {
	/*	
		// for each finished page, try looking for active scripts
		List<String> active = scriptdb.getActive(url);
		Log.d(TAG, String.format("Found %d active scripts on url=%s", active.size(), url));
		if(active.size() == 0) return;
		
		// inject each applicable script into page
		for(String script : active) {
			script = BrowserActivity.this.prepareScript(script);
			webview.loadUrl(script);
			
		}
		*/
		
	}
	
	@Override
	public void onLoadResource(WebView view, String url) {
		// TODO Auto-generated method stub
		super.onLoadResource(view, url);
	}

	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		return false;
	}
	

	
}
